﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BonsaiScrum.Core.Persistance;
using BonsaiScrum.Core.Query;
using NHibernate;
using System.Collections.ObjectModel;
using NHibernate.Criterion;

namespace BonsaiScrum.Data.Reporting
{
    public class NHibernateSprintReportingRepository : ISprintReportingRepository
    {
        private ISession _session;

        public NHibernateSprintReportingRepository(ISession session)
        {
            _session = session;
        }

        public ICollection<SprintReport> GetAllSprints()
        {
            ICriteria criteria = _session.CreateCriteria(typeof(SprintReport));

            return new Collection<SprintReport>(criteria.List<SprintReport>());
        }

        public ICollection<SprintReport> GetAllSprintsInProject(int projectid)
        {
            var sprints = _session.CreateCriteria<SprintReport>()
                .Add(Expression.Eq("ProjectID", projectid))
                .List<SprintReport>();

            return sprints;
        }

        public SprintReport GetSprintWithId(int id)
        {
            return _session.Get<SprintReport>(id);
        }
    }
}